package stc.skymobi.netty.handler;

import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import stc.skymobi.ebus.EventBus;

public class FireEventOnResponseHandler extends ChannelInboundHandlerAdapter {
    private static Logger logger = LoggerFactory.getLogger(FireEventOnResponseHandler.class);

    private EventBus eventBus;
    private String eventResponseReceived;

    @Override
    public void channelActive(ChannelHandlerContext ctx) throws Exception {
        logger.debug("hey,channelConnected");
    }

    @Override
    public void channelInactive(ChannelHandlerContext ctx) throws Exception {
        logger.debug("channelDisconnected");
    }

    @Override
    public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
        logger.debug("fire event {} : {}", eventResponseReceived, msg);
        eventBus.fireEvent(eventResponseReceived, msg);
    }

    public String getEventResponseReceived() {
        return eventResponseReceived;
    }

    public void setEventResponseReceived(String eventResponseReceived) {
        this.eventResponseReceived = eventResponseReceived;
    }

    public void setEventBus(EventBus eventBus) {
        this.eventBus = eventBus;
    }
}
